#pragma once
namespace mini
{
#define SDKMESH_FILE_VERSION 101
#define MAX_VERTEX_ELEMENTS 32
#define MAX_VERTEX_STREAMS 16
#define MAX_FRAME_NAME 100
#define MAX_MESH_NAME 100
#define MAX_SUBSET_NAME 100
#define MAX_MATERIAL_NAME 100
#define MAX_TEXTURE_NAME MAX_PATH
#define MAX_MATERIAL_PATH MAX_PATH
#define MAX_VERTEX_STREAMS 16
	//--------------------------------------------------------------------------------------
	// Structures.  Unions with pointers are forced to 64bit.
	//--------------------------------------------------------------------------------------
	struct SDKMESH_HEADER
	{
		//Basic Info and sizes
		UINT Version;
		BYTE IsBigEndian;
		UINT64 HeaderSize;
		UINT64 NonBufferDataSize;
		UINT64 BufferDataSize;

		//Stats
		UINT NumVertexBuffers;
		UINT NumIndexBuffers;
		UINT NumMeshes;
		UINT NumTotalSubsets;
		UINT NumFrames;
		UINT NumMaterials;

		//Offsets to Data
		UINT64 VertexStreamHeadersOffset;
		UINT64 IndexStreamHeadersOffset;
		UINT64 MeshDataOffset;
		UINT64 SubsetDataOffset;
		UINT64 FrameDataOffset;
		UINT64 MaterialDataOffset;
	};

	struct SDKMESH_VERTEX_BUFFER_HEADER
	{
		UINT64 NumVertices;
		UINT64 SizeBytes;
		UINT64 StrideBytes;
		struct D3DVERTEXELEMENT9
		{
			WORD    Stream;     // Stream index
			WORD    Offset;     // Offset in the stream in bytes
			BYTE    Type;       // Data type
			BYTE    Method;     // Processing method
			BYTE    Usage;      // Semantics
			BYTE    UsageIndex; // Semantic index
		};
		D3DVERTEXELEMENT9 Decl[MAX_VERTEX_ELEMENTS];
		union
		{
			UINT64 DataOffset;				//(This also forces the union to 64bits)
			ID3D11Buffer* pVB11;
		};
	};

	struct SDKMESH_INDEX_BUFFER_HEADER
	{
		UINT64 NumIndices;
		UINT64 SizeBytes;
		UINT IndexType;
		union
		{
			UINT64 DataOffset;				//(This also forces the union to 64bits)
			ID3D11Buffer* pIB11;
		};
	};

	struct SDKMESH_MESH
	{
		char Name[MAX_MESH_NAME];
		BYTE NumVertexBuffers;
		UINT VertexBuffers[MAX_VERTEX_STREAMS];
		UINT IndexBuffer;
		UINT NumSubsets;
		UINT NumFrameInfluences; //aka bones

		D3DXVECTOR3 BoundingBoxCenter;
		D3DXVECTOR3 BoundingBoxExtents;

		union
		{
			UINT64 SubsetOffset;	//Offset to list of subsets (This also forces the union to 64bits)
			UINT* pSubsets;	    //Pointer to list of subsets
		};
		union
		{
			UINT64 FrameInfluenceOffset;  //Offset to list of frame influences (This also forces the union to 64bits)
			UINT* pFrameInfluences;      //Pointer to list of frame influences
		};
	};

	struct SDKMESH_SUBSET
	{
		char Name[MAX_SUBSET_NAME];
		UINT MaterialID;
		UINT PrimitiveType;
		UINT64 IndexStart;
		UINT64 IndexCount;
		UINT64 VertexStart;
		UINT64 VertexCount;
	};

	struct STREAM_OUT_VERTEX
	{
		D3DXVECTOR4 Pos;
		D3DXVECTOR3 Norm;
		D3DXVECTOR2 Tex;
		D3DXVECTOR3 Tangent;
	};

	struct SDKMESH_FRAME
	{
		char Name[MAX_FRAME_NAME];
		UINT Mesh;
		UINT ParentFrame;
		UINT ChildFrame;
		UINT SiblingFrame;
		D3DXMATRIX Matrix;
		UINT AnimationDataIndex;		//Used to index which set of keyframes transforms this frame
	};

	struct SDKMESH_MATERIAL
	{
		char    Name[MAX_MATERIAL_NAME];

		// Use MaterialInstancePath
		char    MaterialInstancePath[MAX_MATERIAL_PATH];

		// Or fall back to d3d8-type materials
		char    DiffuseTexture[MAX_TEXTURE_NAME];
		char    NormalTexture[MAX_TEXTURE_NAME];
		char    SpecularTexture[MAX_TEXTURE_NAME];

		D3DXVECTOR4 Diffuse;
		D3DXVECTOR4 Ambient;
		D3DXVECTOR4 Specular;
		D3DXVECTOR4 Emissive;
		FLOAT Power;

		union
		{
			UINT64 Force64_1;			//Force the union to 64bits
			ID3D11Texture2D* pDiffuseTexture11;
		};
		union
		{
			UINT64 Force64_2;			//Force the union to 64bits
			ID3D11Texture2D* pNormalTexture11;
		};
		union
		{
			UINT64 Force64_3;			//Force the union to 64bits
			ID3D11Texture2D* pSpecularTexture11;
		};

		union
		{
			UINT64 Force64_4;			//Force the union to 64bits
			ID3D11ShaderResourceView* pDiffuseRV11;
		};
		union
		{
			UINT64 Force64_5;		    //Force the union to 64bits
			ID3D11ShaderResourceView* pNormalRV11;
		};
		union
		{
			UINT64 Force64_6;			//Force the union to 64bits
			ID3D11ShaderResourceView* pSpecularRV11;
		};

	};
	struct SDKANIMATION_FILE_HEADER
	{
		UINT Version;
		BYTE IsBigEndian;
		UINT FrameTransformType;
		UINT NumFrames;
		UINT NumAnimationKeys;
		UINT AnimationFPS;
		UINT64 AnimationDataSize;
		UINT64 AnimationDataOffset;
	};
	struct SDKANIMATION_DATA
	{
		D3DXVECTOR3 Translation;
		D3DXVECTOR4 Orientation;
		D3DXVECTOR3 Scaling;
	};

	struct SDKANIMATION_FRAME_DATA
	{
		char FrameName[MAX_FRAME_NAME];
		union
		{
			UINT64 DataOffset;
			SDKANIMATION_DATA* pAnimationData;
		};
	};
}